package net.jiug.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 验证工具
 *
 * @author keffett
 * @date 2018-11-23
 */
public class ValidationUtil {

    /**
     * 验证空
     */
    public static boolean isNull(Object obj) {
        return null == obj || obj.equals((Object)null);
    }
    public static boolean isEmpty(String str) {
        return null == str || "".equals(str);
    }

    /**
     * 验证是否为邮箱
     */
//    public static boolean isEmail(String email) {
//        return Validator.isEmail(email);
//    }
    public static boolean isEmail(String email) {

        if (isEmpty(email)) return false;

        String regex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}
